package lei.j_java泛型_匿名内部类_反射.泛型.通配符;

/**
 * @className: 无界通配符
 * @author: xl
 * @date: 2025/3/1 16:19
 * @Version: 1.0
 * @description:
 */

import java.util.List;

public class 无界通配符 {
    // 使用无界通配符
    public static void printList(List<?> list) {
        for (Object element : list) {
            System.out.print(element + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        var intList = List.of(1, 2, 3);
        List<String> strList = List.of("A", "B", "C");

        printList(intList); // 输出: 1 2 3
        printList(strList); // 输出: A B C
    }
}

